package top.jiangqiang.qyblog.admin.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;
import top.jiangqiang.qyblog.common.base.controller.BaseController;
import top.jiangqiang.qyblog.common.base.query.PageResult;
import top.jiangqiang.qyblog.common.base.response.Result;
import top.jiangqiang.qyblog.common.constant.RequestURLConstants;
import top.jiangqiang.qyblog.core.domain.dto.NavAddDto;
import top.jiangqiang.qyblog.core.domain.dto.NavQueryDto;
import top.jiangqiang.qyblog.core.domain.dto.NavUpdateDto;
import top.jiangqiang.qyblog.core.domain.vo.NavVo;
import top.jiangqiang.qyblog.core.service.INavService;

/**
 * @author jiangqiang
 * @date 2022-11-27
 */
@RequiredArgsConstructor
@RestController
@RequestMapping(RequestURLConstants.BLOG_NAV_CONTROLLER_PREFIX)
@Tag(name = "博客导航菜单接口")
public class NavController extends BaseController {
    private final INavService navService;

    @GetMapping
    @Operation(summary = "根据条件查询博客菜单列表", description = "支持分页，排序等功能，此接口查询到的菜单的children属性会关联到他的子菜单，所以可以直接查询出树形结构。")
    public Result<PageResult<NavVo>> list(@ParameterObject NavQueryDto navQueryDto) {
        return navService.findByCondition(navQueryDto);
    }

    @GetMapping("/{id}")
    @Operation(summary = "查询菜单详情", description = "查询菜单详情")
    public Result<NavVo> get(@PathVariable Long id) {
        return navService.getNav(id);
    }

    @PostMapping
    @Operation(summary = "新增菜单导航", description = "新增一个菜单")
    public Result<NavVo> save(@RequestBody NavAddDto navAddDto) {
        return navService.saveNav(navAddDto);
    }

    @PutMapping
    @Operation(summary = "编辑菜单导航", description = "根据id修改一个菜单")
    public Result<NavVo> update(@RequestBody NavUpdateDto navUpdateDto) {
        return navService.editNav(navUpdateDto);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除菜单导航", description = "根据id删除一个菜单")
    public Result<Boolean> delete(@PathVariable Long id) {
        return navService.deleteNav(id);
    }

}
